package com.jcl.cloud.services.crawler.email.service;


import com.jcl.cloud.services.crawler.email.constant.TaskInfo;
import com.jcl.cloud.services.crawler.email.task.CatchEmailHandler;
import com.jcl.cloud.services.crawler.email.task.CatchEmailHandlerWrap;
import com.jcl.cloud.services.crawler.email.task.QcwyCatchEmailHandler;
import com.jcl.cloud.services.crawler.email.task.ZlzpCatchEmailHandler;
import com.jcl.cloud.services.crawler.email.util.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CatchEmailManagerService {

    @Autowired
    private RedisService redisService;
    @Autowired
    private ThreadMonitorService threadMonitorService;


    public void createCatchEmailTask(String crawlerId){

        String siteCode = this.redisService.hget("unicrawler:task:info:"+crawlerId,"siteCode");
        /*if(TaskInfo.runningTask.contains(crawlerId)){
            //放入任务锁的map中
            TaskInfo.taskLockMap.put(crawlerId,siteCode);
        }else{*/
            CatchEmailHandler catchEmailHandler = null;
            if("QCWY".equalsIgnoreCase(siteCode)){
                catchEmailHandler = (CatchEmailHandler) ContextUtil.getContext().getBean("qcwyCatchEmailHandler");
            }else if("ZLZP".equalsIgnoreCase(siteCode)){
                catchEmailHandler = (CatchEmailHandler) ContextUtil.getContext().getBean("zlzpCatchEmailHandler");
            }
            //new Thread(new CatchEmailHandlerWrap(catchEmailHandler,crawlerId)).start();
            this.threadMonitorService.execute(new CatchEmailHandlerWrap(catchEmailHandler,crawlerId),crawlerId);
        /*    TaskInfo.runningTask.put(crawlerId,siteCode);
        }*/
    }
}
